package com.ev.k3cloudBusiness.service.impl;

import com.alibaba.fastjson.JSON;
import com.ev.k3cloud.entity.K3CloudBillQueryEntity;
import com.ev.k3cloud.enums.K3CloudBillFormId;
import com.ev.k3cloud.service.K3CloudService;
import com.ev.k3cloudBusiness.service.K3ReceivableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class K3ReceivableServiceImpl implements K3ReceivableService {
    @Autowired
    K3CloudService k3CloudService;

    @Override
    public Integer getBySourceBillNo(String sourceBillNo) {
        K3CloudBillQueryEntity queryEntity = new K3CloudBillQueryEntity();
        queryEntity.setFieldKeys("FID");
        queryEntity.setFilterString("FSourceBillNo = '" + sourceBillNo + "'");
        queryEntity.setFormId(K3CloudBillFormId.AR_RECEIVABLE.getFormId());
        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("data", queryEntity);
        String result = k3CloudService.billQuery(JSON.toJSONString(dataMap));
        if (result.equals("[]")) {
            return 0;
        }
        else {
            return 1;
        }
    }
}
